package KiemTra;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Bai02 extends JFrame implements Runnable{
	
	JPanel canvas = new JPanel();
	
	public Bai02(){
		this.setSize(416, 440);
		this.setVisible(true);
		this.add(canvas);
		new Thread(this).start();
	}
	
	public static void main(String[] args) {
		Bai02 frm = new Bai02();

	}

	@Override
	public void run() {
		int ct = 200;
		int i =ct;	
		Color c = new Color((int)(255.0*Math.random()),(int)(255.0*Math.random()),(int)(255.0*Math.random()));
		while(true){
			while(i >= 0){
				Graphics g = canvas.getGraphics();
				//Trên
				int kc = (ct - i) * 2;
				g.setColor(Color.BLUE);
				g.drawLine(i, i, kc + i, i);
				System.out.println("Trên:" + i);
				//Dưới
				c = new Color((int)(255.0*Math.random()),(int)(255.0*Math.random()),(int)(255.0*Math.random()));
				g.setColor(Color.RED);
				g.drawLine(i, kc + i, kc + i, kc + i);
				
				//Trái
				c = new Color((int)(255.0*Math.random()),(int)(255.0*Math.random()),(int)(255.0*Math.random()));
				g.setColor(Color.YELLOW);
				g.drawLine(i, i, i, i + kc);
				
				//Phải
				c = new Color((int)(255.0*Math.random()),(int)(255.0*Math.random()),(int)(255.0*Math.random()));
				g.setColor(Color.GREEN);
				g.drawLine(i + kc, i, i + kc, i + kc);
				
				i--;
				try{ 
					Thread.sleep(10);
				}
				catch(Exception e){}	
			}
			
			while(i <= ct){
				Graphics g = canvas.getGraphics();
				//Trên
				int kc = (ct - i) * 2;
				g.setColor(Color.RED);
				g.drawLine(i, i, kc + i, i);
				System.out.println("Trên:" + i);
				//Dưới
				c = new Color((int)(255.0*Math.random()),(int)(255.0*Math.random()),(int)(255.0*Math.random()));
				g.setColor(Color.BLUE);
				g.drawLine(i, kc + i, kc + i, kc + i);
				
				//Trái
				c = new Color((int)(255.0*Math.random()),(int)(255.0*Math.random()),(int)(255.0*Math.random()));
				g.setColor(Color.GREEN);
				g.drawLine(i, i, i, i + kc);
				
				//Phải
				c = new Color((int)(255.0*Math.random()),(int)(255.0*Math.random()),(int)(255.0*Math.random()));
				g.setColor(Color.YELLOW);
				g.drawLine(i + kc, i, i + kc, i + kc);
				
				i++;
				try{ 
					Thread.sleep(10);
				}
				catch(Exception e){}	
			}
		}
	}

}
